package com.cdream.basic.algorithm.leetcode.linkedlist;

/**
 * @author cdream
 * @date 6/13/21
 */
public class Question24 {
    public ListNode swapPairs(ListNode head) {
        ListNode dummy = new ListNode(-1);

        dummy.next = head;
        ListNode cur = dummy;
        while (cur.next != null && cur.next.next != null) {
            ListNode p1 = cur.next;
            ListNode p2 = cur.next.next;

            p1.next = p2.next;
            p2.next = p1;
            cur.next = p2;
            cur = p1;
        }
        return dummy.next;
    }
}
